using System.Linq;
using System.Linq.Expressions;
using System.Reflection;

namespace DapperExtensionsNew.Queryable.Analyzers
{
	public abstract class Where : AbstractAnalyzer
	{
		protected override void Analyze(Context context)
		{
			PropertyInfo[] array = context.QueryProperties.Where((PropertyInfo p) => IsSatisfied(context, p)).ToArray();
			foreach (PropertyInfo queryProperty in array)
			{
				context.Statements.Add(Expression.Block(GetWhereClause(context, queryProperty)));
			}
		}

		protected abstract bool IsSatisfied(Context context, PropertyInfo queryProperty);

		protected abstract Expression GetWhereClause(Context context, PropertyInfo queryProperty);
	}
}
